package net.jeeshop.web.action.manage.task;
import java.util.Iterator;
import java.util.Map.Entry;
import org.apache.commons.lang.StringUtils;
import net.jeeshop.core.BaseAction;
import net.jeeshop.core.TaskManager;
import net.jeeshop.services.manage.task.TaskService;
import net.jeeshop.services.manage.task.bean.Task;
public class TaskAction extends BaseAction<Task> {
    private static final long serialVersionUID = 1L;
    private TaskService taskService;
    private TaskManager taskManager;
    public void setTaskManager(TaskManager taskManager) {
        this.taskManager = taskManager;
    }
    public TaskService getTaskService() {
        return taskService;
    }
    protected void selectListAfter() {
        pager.setPagerUrl("task!selectList.action");
    }
    public void setTaskService(TaskService taskService) {
        this.taskService = taskService;
    }
    public Task getE() {
        return this.e;
    }
    public void prepare() throws Exception {
        if (this.e == null) {
            this.e = new Task();
        }
    }
    public void insertAfter(Task e) {
        e.clear();
    }
    @Override
    public String selectList() throws Exception {
        super.selectList();
        if(pager.getList()!=null){
            for(int i=0;i<pager.getList().size();i++){
                Task item = (Task) pager.getList().get(i);
                Task task = TaskManager.getTask(item.getCode());
                if(task!=null){
                    item.setNextWorkTime(task.getNextWorkTime());
                    if(task.getThread()!=null){
                        item.setCurrentStatus(task.getThread().getState().name());
                    }else{
                        item.setCurrentStatus;
                    }
                }
            }
        }
        return toList;
    }
    public String startTask() throws Exception{
        if(StringUtils.isBlank(e.getCode())){
        }
        Task task = taskManager.getTask(e.getCode());
        if(task==null){
        }
        task.getThread().
        return selectList();
    }
    public String stopTask() throws Exception{
        if(StringUtils.isBlank(e.getCode())){
        }
        return selectList();
    }
}
package net.jeeshop.web.action.manage.system;
        import java.io.IOException;
        import java.util.ArrayList;
        import java.util.HashMap;
        import java.util.Iterator;
        import java.util.List;
        import java.util.Map;
        import java.util.TreeMap;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import net.jeeshop.core.BaseAction;
        import net.jeeshop.core.ManageContainer;
        import net.jeeshop.core.Services;
        import net.jeeshop.core.system.bean.Menu;
        import net.jeeshop.core.system.bean.MenuItem;
        import net.jeeshop.core.system.bean.MenuType;
        import net.jeeshop.core.system.bean.Privilege;
        import net.jeeshop.core.system.bean.User;
        import net.jeeshop.services.manage.system.impl.MenuService;
        import net.jeeshop.services.manage.system.impl.PrivilegeService;
        import net.sf.json.JSONArray;
public class MenuAction extends BaseAction<Menu> {
    private static final long serialVersionUID = 1L;
    private MenuService menuService;
    private PrivilegeService privilegeService;
    private static final String str = "../";
    private Menu menu = new Menu();
    private static final Logger log = LoggerFactory.getLogger(MenuAction.class);
    public PrivilegeService getPrivilegeService() {
        return privilegeService;
    }
    public void setPrivilegeService(PrivilegeService privilegeService) {
        this.privilegeService = privilegeService;
    }
    @Override
    protected void selectListAfter() {
        pager.setPagerUrl("menu!selectList.action");
    }
    public String toAddOrUpdate() throws Exception{
        System.out.println(menu!=null?menu.getId():"null");
        menu.clear();
        System.out.println("==="+getRequest().getParameter("id"));
        menu.setId(getRequest().getParameter("id"));
        menu = menuService.selectOne(menu);
        return "addOrUpdate";
        return toList;
    }
    public String addOrUpdate() throws Exception{
        String updateP = getRequest().getParameter("updateP");
        String id = getRequest().getParameter("id");
        String name = getRequest().getParameter("name");
        String orderNum = getRequest().getParameter("orderNum");
        String type = getRequest().getParameter("type");
        String url = getRequest().getParameter("url");
        String n_name = getRequest().getParameter("n_name");
        String n_url = getRequest().getParameter("n_url");
        String parentOrChild = getRequest().getParameter("parentOrChild");
        String n_orderNum = getRequest().getParameter("n_orderNum");
        String n_type = getRequest().getParameter("n_type");
        Menu itemMenu = null;
        if(n_name!=null && !n_name.trim().equals("")){
            itemMenu = new Menu();
            if(parentOrChild.equals("0")){
                itemMenu.setPid("0");
                itemMenu.setType(MenuType.module.toString());
            } else if(parentOrChild.equals("1")){
                itemMenu.setPid("0");
                itemMenu.setType(MenuType.page.toString());
            } else if(parentOrChild.equals("2")){
                itemMenu.setPid(id);
                itemMenu.setType(MenuType.module.toString());
            } else if(parentOrChild.equals("3")){
                itemMenu.setPid(id);
                itemMenu.setType(MenuType.page.toString());
            } else if(parentOrChild.equals("4")){
                itemMenu.setPid(id);
                itemMenu.setType(MenuType.button.toString());
            } else {
                throw new IllegalAccessException;
            }
            itemMenu.setName(n_name);
            itemMenu.setUrl(n_url);
            itemMenu.setOrderNum(Integer.valueOf(n_orderNum));
            itemMenu.setType(n_type);
        }
        Menu m = new Menu();
        m.setId(id);
        m.setName(name);
        m.setUrl(url);
        m.setOrderNum(Integer.valueOf(orderNum));
        m.setType(type);
        menuService.addOrUpdate(updateP,m, itemMenu);
        getResponse().getWriter().print("ok");
        return null;
    }
    public String selectJsonMenu() throws Exception {
        Object menusJson = getSession().getAttribute(ManageContainer.resource_menus);
        if(menusJson!=null){
            getResponse().getWriter().write(menusJson.toString());
        }else{
            User u = (User) getSession().getAttribute(ManageContainer.manage_session_user_info);
            List<MenuItem> root = loadMenus(u,"0",null);
            getSession().setAttribute(ManageContainer.resource_menus, writeMenus(root));
            if(root!=null){
                for(int i=0;i<root.size();i++){
                    MenuItem item = root.get(i);
                    if(item.get)
                }
                getSession().setAttribute(ManageContainer.user_resource_menus_button,null);
            }
        }
        return null;
    }
    private static void setBucketPublicReadable(OSSClient client, String bucketName)
            throws OSSException, ClientException {
        client.createBucket(bucketName);
        client.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
    }
    class NameComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                return ((String)hashA.get("filename")).compareTo((String)hashB.get("filename"));
            }
        }
    }
    class SizeComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                if (((Long)hashA.get("filesize")) > ((Long)hashB.get("filesize"))) {
                    return 1;
                } else if (((Long)hashA.get("filesize")) < ((Long)hashB.get("filesize"))) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    }
    private void addUserResourceMenusButton(String button){
        log.debug("addUserResourceMenusButton.button="+button);
        Map<String,String> buttons = (Map<String, String>)
                getSession().getAttribute(ManageContainer.user_resource_menus_button);
        if(buttons==null){
            buttons = new HashMap<String, String>();TreeMap<String, String>();
            getSession().setAttribute(ManageContainer.user_resource_menus_button,buttons);
        }
        buttons.put(button, button);
    }
    public void getMenusByPid() throws Exception {
        String pid = getRequest().getParameter("pid");
        if(pid==null || pid.trim().equals(""))
            pid = "0";
        String id = getRequest().getParameter("id");
        List<MenuItem> menus = menuService.loadMenus(null, pid, "#");
        Privilege privilege = new Privilege();
        privilege.setRid(id);
        List<Privilege> rolePs = privilegeService.selectList(privilege);
        for (int i = 0; i < rolePs.size(); i++) {
            Privilege p = rolePs.get(i);
            eeee(p, menus);
        }
    }
    writeMenus(menus);
}
    private void eeee(Privilege p,List<MenuItem> menus){
        for (int j = 0; j < menus.size(); j++) {
            MenuItem menu = menus.get(j);
            if (p.getMid().equals(menu.getId())) {
                menu.setChecked(true);
                return;
            }else{
                if(menu.getChildren()!=null && menu.getChildren().size()>0)
                    eeee(p, menu.getChildren());
            }
        }
    }
    private String writeMenus(List<MenuItem> root) throws IOException{
        JSONArray json = JSONArray.fromObject(root);
        System.out.println(json.toString());
        String jsonStr = json.toString();
        try {
            getResponse().getWriter().write(jsonStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonStr;
    }
    private List<MenuItem> loadMenus(User u,String pid,String url) {
        Map<String,String> param = new HashMap<String, String>();
        if(u!=null && u.getRid()!=null){
            param.put("rid", u.getRid());
        }
        param.put("pid", pid);
        List<Menu> menus = menuService.selectList(param);
        List<MenuItem> root = new ArrayList<MenuItem>();
        for (Iterator<Menu> it = menus.iterator(); it.hasNext();) {
            Menu entry = it.next();
            MenuItem item = new MenuItem(entry.getName(), null);
            item.setId(entry.getId());
            item.setPid(entry.getPid());
            item.setMenuType(entry);
            if(item.getType().equals(MenuType.page)){
            }
            if(url!=null){
                item.setUrl(url);
            }else{
                item.setUrl(entry.getUrl());
            }
            root.add(item);
        }
        for (int i = 0; i < root.size(); i++) {
            MenuItem item = root.get(i);
            if(!item.isButton()){
                Menu mm = new Menu();
                mm.setPid(item.getId());
                loadChildrenByPid(root.get(i), mm,url,u);
            }else{
                addUserResourceMenusButton(item.getUrl());
            }
        }
        return root;
    }
    private void loadChildrenByPid(MenuItem item, Menu menu,String url,User u) {
        Map<String,String> param = new HashMap<String, String>();
        if(u!=null && u.getRid()!=null)
            param.put("rid", u.getRid());
        param.put("pid", menu.getPid());
        List<Menu> data = menuService.selectList(param);
        if(data==null || data.size()==0){
            return;
        }
        if(item.getChildren()==null)item.setChildren(new ArrayList<MenuItem>());
        for (int i = 0; i < data.size(); i++) {
            Menu entry = data.get(i);
            MenuItem addItem = new MenuItem(entry.getName(), null);
            addItem.setId(entry.getId());
            addItem.setPid(entry.getPid());
            addItem.setMenuType(entry);
            String url0 = null;
            if(url!=null){
                addItem.setUrl(str+url);
                url0 = url;
            }else{
                addItem.setUrl(str+entry.getUrl());
                url0 = entry.getUrl();
            }	System.out.println("entry.getType()="+entry.getType()+",MenuType.button="+MenuType.button);
            if(entry.getType().equals("button")){
                addUserResourceMenusButton(url0);
            }else{
                item.getChildren().add(addItem);
            }
        }
        for (int i = 0; i < item.getChildren().size(); i++) {
            MenuItem childItem = item.getChildren().get(i);
            if(!childItem.isButton()){
                Menu itemMenu = new Menu();
                itemMenu.setPid(childItem.getId());
                itemMenu.setMenuType(entry);
                loadChildrenByPid(childItem, itemMenu,url,u);
            }
        }
    }
    public String save() throws Exception {
        if (menu.getId() == null || menu.getId().equals("")) {
            if (menu.getUrl() == null) {
                menu.setUrl("");
            }
            menuService.insert(menu);
        } else {
            menuService.update(menu);
        }
        return selectList();
    }
    public String delete() throws Exception {
        String ids = getRequest().getParameter("ids");
        if(ids==null || ids.trim().equals(""))
            this.menuService.deletes(ids,getRequest().getParameter("deleteParent"));
        getResponse().getWriter().println("1");
        return null;
    }
    public MenuService getMenuService() {
        return menuService;
    }
    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }
    public Menu getMenu() {
        return menu;
    }
    public void setMenu(Menu menu) {
        this.menu = menu;
    }
    @Override
    public Menu getE() {
        TODO Auto-generated method stub
        return this.menu;
    }
    @Override
    public Services<Menu> getServer() {
        TODO Auto-generated method stub
        return this.menuService;
    }
    @Override
    public void prepare() throws Exception {
        TODO Auto-generated method stub
        if(menu==null){
            menu = new Menu();
        }
    }
    @Override
    public void insertAfter(Menu e) {
        TODO Auto-generated method stub
        e.clear();
    }
}
package net.jeeshop.web.action.manage.systemSetting;
        import java.util.HashMap;
        import java.util.HashSet;
        import java.util.Iterator;
        import java.util.LinkedList;
        import java.util.Map;
        import java.util.Set;
        import net.jeeshop.core.BaseAction;
        import net.jeeshop.core.ManageContainer;
        import net.jeeshop.core.oscache.FrontCache;
        import net.jeeshop.services.manage.systemSetting.SystemSettingService;
        import net.jeeshop.services.manage.systemSetting.bean.BelieveLoginInfo;
        import net.jeeshop.services.manage.systemSetting.bean.SystemSetting;
        import org.apache.commons.lang.StringUtils;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import com.alibaba.fastjson.JSON;
public class SystemSettingAction extends BaseAction<SystemSetting> {
    private static final Logger logger = LoggerFactory.getLogger(SystemSetting.class);
    private static final long serialVersionUID = 1L;
    private SystemSettingService systemSettingService;
    private FrontCache frontCache;
    private String sync;
    private String[] imagePaths;
    public String[] getImagePaths() {
        return imagePaths;
    }
    public void setImagePaths(String[] imagePaths) {
        this.imagePaths = imagePaths;
    }
    public FrontCache getFrontCache() {
        return frontCache;
    }
    public void setFrontCache(FrontCache frontCache) {
        this.frontCache = frontCache;
    }
    public String getSync() {
        return sync;
    }
    public void setSync(String sync) {
        this.sync = sync;
    }
    public SystemSettingService getSystemSettingService() {
        return systemSettingService;
    }
    protected void selectListAfter() {
        pager.setPagerUrl("systemSetting!selectList.action");
    }
    public void setSystemSettingService(
            SystemSettingService systemSettingService) {
        this.systemSettingService = systemSettingService;
    }
    public SystemSetting getE() {
        return this.e;
    }
    public void prepare() throws Exception {
        if (this.e == null) {
            this.e = new SystemSetting();
        }
    }
    public void insertAfter(SystemSetting e) {
        e.clear();
    }
    public String insertOrupdate() throws Exception {
        synchronized (this) {
            e.setBelieveLoginConfig(e.getBelieveLoginInfo().getJsonStr());
            if(StringUtils.isEmpty(e.getId())){
                e.setImages(getImagesPath(null));
                insert();
            }else{
                SystemSetting ss = systemSettingService.selectById(e.getId());
                if(ss==null){
                }
                e.setImages(getImagesPath(ss.getImages()));
                super.update();
            }
            logger.error("sync="+sync);
            frontCache.loadAllCache();
            if(StringUtils.isNotBlank(sync) && Boolean.valueOf(sync)){
                cacheManager.loadAllCache();
            }
        }
        return toEdit();
    }
    @Override
    public String toEdit() throws Exception {
        super.toEdit();
        if(StringUtils.isNotBlank(e.getImages())){
            if(e.getImagesList()==null){
                e.setImagesList(new LinkedList<String>());
            }else{
                e.getImagesList().clear();
            }
            String[] imageArr = e.getImages().split(ManageContainer.product_images_spider);
            for(int i=0;i<imageArr.length;i++){
                e.getImagesList().add(imageArr[i]);
            }
        }
        logger.error(">>e.getBelieveLoginConfig() = " + e.getBelieveLoginConfig());
        if(StringUtils.isNotBlank(e.getBelieveLoginConfig())){
            e.setBelieveLoginInfo(JSON.parseObject(e.getBelieveLoginConfig(), BelieveLoginInfo.class));
            logger.error(">>believeLoginInfo = " + e.getBelieveLoginInfo().toString());
        }
        return toEdit;
    }
    private String getImagesPath(String appendImgs){
        logger.error("e.images = "+e.getImages());
        Set<String> imagesSet = new HashSet<String>();
        if(StringUtils.isNotBlank(appendImgs)){
            String[] images2 = appendImgs.split(ManageContainer.product_images_spider);
            for(int i=0;i<images2.length;i++){
                if(StringUtils.isNotBlank(images2[i])){
                    imagesSet.add(images2[i].trim());
                }
            }
        }
        String[] images = e.getImages().split(ManageContainer.product_images_spider);
        for(int i=0;i<images.length;i++){
            if(StringUtils.isNotBlank(images[i])){
                imagesSet.add(images[i].trim());
            }
        }
        StringBuilder buff = new StringBuilder();
        for(Iterator<String> it = imagesSet.iterator();it.hasNext();){
            buff.append(it.next()+",");
        }
        String rr = buff.toString();
        if(rr.length()>0 && rr.endsWith(ManageContainer.product_images_spider)){
            rr = rr.substring(0, rr.length()-1);
        }
        return rr;
    }
    public String deleteImageByImgPaths() throws Exception{
        String id = e.getId();
        if(imagePaths!=null & imagePaths.length>0){
            SystemSetting ee = systemSettingService.selectById(id);
            if(StringUtils.isNotBlank(ee.getImages())){
                String[] images = ee.getImages().split(ManageContainer.product_images_spider);
                for(int i=0;i<imagePaths.length;i++){
                    for(int j=0;j<images.length;j++){
                        if(imagePaths[i].equals(images[j])){
                            images[j] = null;
                            break;
                        }
                    }
                    imagePaths[i] = null;
                }
                StringBuilder buff = new StringBuilder();
                for(int j=0;j<images.length;j++){
                    if(images[j]!=null){
                        buff.append(images[j]+",");
                    }
                }
                ee.clear();
                ee.setId(id);
                ee.setImages(buff.toString());
                if(ee.getImages().equals("")){
                    ee.setImages(ManageContainer.product_images_spider);
                }
                systemSettingService.update(ee);
            }
            imagePaths = null;
        }
        getResponse().sendRedirect(getEditUrl(id));
        return null;
        return toEdit();
    }
    private String getEditUrl(String id){
        return "systemSetting!toEdit.action?e.id="+id;
    }
    public static void main(String[] args) {
        Map<String, Map<String, String>> map = new HashMap<String, Map<String,String>>();
        Map<String, String> qqMap = new HashMap<String, String>();
        qqMap.put("app_ID", "101020775");
        qqMap.put("app_KEY", "dca110b976f2a72a7d3fd283fe35d6ec");
        Map<String, String> sinawbMap = new HashMap<String, String>();
        sinawbMap.put("app_ID", "101020775");
        sinawbMap.put("app_KEY", "dca110b976f2a72a7d3fd283fe35d6ec");
        map.put("qq", qqMap);
        map.put("sinawb", sinawbMap);
        System.out.println(JSON.toJSONString(map));
    }
}
package net.jeeshop.web.action.manage.systemlog;
        import net.jeeshop.core.BaseAction;
        import net.jeeshop.services.manage.systemlog.SystemlogService;
        import net.jeeshop.services.manage.systemlog.bean.Systemlog;
        import org.apache.commons.lang.StringUtils;
public class SystemlogAction extends BaseAction<Systemlog> {
    private static final long serialVersionUID = 1L;
    private SystemlogService systemlogService;
    public SystemlogService getSystemlogService() {
        return systemlogService;
    }
    protected void selectListAfter() {
        pager.setPagerUrl("systemlog!selectList.action");
    }
    public void setSystemlogService(SystemlogService systemlogService) {
        this.systemlogService = systemlogService;
    }
    public Systemlog getE() {
        return this.e;
    }
    public void prepare() throws Exception {
        if (this.e == null) {
            this.e = new Systemlog();
        }
        super.initPageSelect();
    }
    public void insertAfter(Systemlog e) {
        e.clear();
    }
    public String systemlogListAndDetail() throws Exception{
        String type = getRequest().getParameter("type");
        if(StringUtils.isNotBlank(type)){
            e.setType(Integer.valueOf(type));
        }
        selectList();
        return "systemlogListAndDetail";
    }
}
package net.jeeshop.web.action.manage.system;
        import net.jeeshop.core.BaseAction;
        import net.jeeshop.core.ManageContainer;
        import net.jeeshop.core.Services;
        import net.jeeshop.core.exception.NotThisMethod;
        import net.jeeshop.core.system.bean.Role;
        import net.jeeshop.core.system.bean.User;
        import net.jeeshop.services.manage.system.impl.MenuService;
        import net.jeeshop.services.manage.system.impl.RoleService;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import com.aliyun.common.comm.ServiceClient.Request;
public class RoleAction extends BaseAction<Role> {
    private static final long serialVersionUID = 1L;
    private static final Logger logger = LoggerFactory.getLogger(RoleAction.class);
    private RoleService roleService;
    private MenuService menuService;
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }
    public void setMenuService(MenuService menuService) {
        this.menuService = menuService;
    }
    private Role role = new Role();
    public String save() throws Exception {
        Role r = new Role();
        r.setRole_name(getRequest().getParameter("roleName"));
        r.setId(getRequest().getParameter("id"));
        r.setRole_desc(getRequest().getParameter("roleDesc"));
        r.setRole_dbPrivilege(getRequest().getParameter("role_dbPrivilege"));
        r.setPrivileges(getRequest().getParameter("privileges"));
        r.setStatus(getRequest().getParameter("status"));
        if(r.getRole_name()==null || r.getRole_name().trim().equals("")){
            getResponse().getWriter().print("0");
            return null;
        }else{
            roleService.editRole(r,getRequest().getParameter("insertOrUpdate"));
        }
        getResponse().getWriter().write("1");
        return null;
    }
    @Override
    public String deletes() throws Exception {
        throw new NotThisMethod(ManageContainer.not_this_method);
    }
    private static void setBucketPublicReadable(OSSClient client, String bucketName)
            throws OSSException, ClientException {
        client.createBucket(bucketName);
        client.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);
    }
    class NameComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                return ((String)hashA.get("filename")).compareTo((String)hashB.get("filename"));
            }
        }
    }
    class SizeComparator implements Comparator<Object> {
        public int compare(Object a, Object b) {
            Hashtable hashA = (Hashtable)a;
            Hashtable hashB = (Hashtable)b;
            if (((Boolean)hashA.get("is_dir")) && !((Boolean)hashB.get("is_dir"))) {
                return -1;
            } else if (!((Boolean)hashA.get("is_dir")) && ((Boolean)hashB.get("is_dir"))) {
                return 1;
            } else {
                if (((Long)hashA.get("filesize")) > ((Long)hashB.get("filesize"))) {
                    return 1;
                } else if (((Long)hashA.get("filesize")) < ((Long)hashB.get("filesize"))) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    }
    public String delet() throws Exception {
        logger.error("role.delete...");
        throw new NotThisMethod(ManageContainer.not_this_method);
        if(getIds()!=null && getIds().length>0){
            for(int i=0;i<getIds().length;i++){
                if(getIds()[i].equals("1")){
                }
            }
            roleService.deletes(getIds());
        }
        return selectList();
    }
    getter setter
    public Role getRole() {
        return role;
    }
    public void setRole(Role role) {
        this.role = role;
    }
    @Override
    public Role getE() {
        TODO Auto-generated method stub
        return this.role;
    }
    @Override
    public Services<Role> getServer() {
        TODO Auto-generated method stub
        return this.roleService;
    }
    @Override
    public void prepare() throws Exception {
        TODO Auto-generated method stub
        String id = getRequest().getParameter("id");
        if (id==null || id.trim().equals("")){
            role.clear();
            role.setInsertOrUpdate("1");
        }
        else{
            role.clear();
            role.setId(id);
            role = roleService.selectOne(role);
            if (role == null) {
                role = new Role();
            }
            role.setInsertOrUpdate("2");
        }
        if(e==null){
            e = new Role();
        }
    }
    @Override
    public void insertAfter(Role e) {
        e.clear();
    }
    @Override
    protected void selectListAfter() {
        pager.setPagerUrl("role!selectList.action");
    }
    @Override
    public String update() throws Exception {
        User user =
                (User)getRequest().getSession().getAttribute(ManageContainer.manage_session_user_info);
        if(!user.getUsername().equals("admin")){
            throw new NullPointerException(ManageContainer.RoleAction_update_error);
        }
        return super.update();
    }
}
package net.jeeshop.core.interceptor;
        import java.io.PrintWriter;
        import java.io.StringWriter;
        import net.jeeshop.core.ManageContainer;
        import net.jeeshop.core.system.bean.User;
        import net.jeeshop.web.action.manage.system.MenuAction;
        import net.jeeshop.web.action.manage.system.UserAction;
        import org.apache.commons.lang.StringUtils;
        import org.apache.struts2.ServletActionContext;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import com.opensymphony.xwork2.ActionInvocation;
        import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class ManageInterceptor extends AbstractInterceptor {
    private static final long serialVersionUID = 1L;
    private static final Logger logger = LoggerFactory.getLogger(ManageInterceptor.class);
    public static final String login = "login";
    public static final String error = "error";
    public static final String not_privilege = "not_privilege";
    public static final String not_db_privilege = "not_db_privilege";
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        logger.error("ManageInterceptor.intercept...");
        try {
            return intercept0(actionInvocation);
        } catch (Throwable e) {
            e.printStackTrace();
            String msg = e.getMessage();
            logger.error("msg="+msg);
            if(StringUtils.isNotBlank(msg)){
                ServletActionContext.getRequest().getSession().setAttribute(ManageContainer.action_exception_error, msg);
            }else{
            }
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            ServletActionContext.getRequest().getSession().setAttribute(ManageContainer.action_exception_stack_error, sw.getBuffer().toString());
        }
        return error;
    }
    private String intercept0(ActionInvocation actionInvocation) throws Exception {
        String actionName = actionInvocation.getProxy().getActionName();
        Object action = actionInvocation.getProxy().getAction();
        String method = actionInvocation.getProxy().getMethod();
        String namespace = actionInvocation.getProxy().getNamespace();
        Object action2 = actionInvocation.getAction();
        if(StringUtils.isBlank(method)){
            throw new NullPointerException;
        }		logger.error(">>ManageInterceptor==actionName="+actionName+";method="+method+";action="+action+";namespace="+namespace);
        logger.error(">>ManageInterceptor==actionName="+actionName+";method="+method+";action="+action+";namespace="+namespace+";action2="+action2);
        String url = actionName+"!"+method+".action";
        StringBuffer urlBuff = new StringBuffer(actionName);
        urlBuff.append("!").append(method).append(".action");
        actionInvocation.getInvocationContext().
        if (action2 instanceof UserAction || action2 instanceof MenuAction) {
            return actionInvocation.invoke();
        }
        HttpSession session = ServletActionContext.getRequest().getSession();
        User user = (User)
                ServletActionContext.getRequest().getSession().getAttribute(ManageContainer.manage_session_user_info);
        if(user==null){
            ServletActionContext.getResponse().sendRedirect(SystemManager.systemSetting.getManageHttp()+"/error.jsp");
            return login;
        }
        if(user.getUsername().equals("admin")){
            return actionInvocation.invoke();
        }
        if(user.getUsername().equals("test1")){
            if((actionName.equals("pay") && method.equals("toEdit"))
                    || actionName.equals("oss") && method.equals("toEdit")){
                return not_db_privilege;
            }
        }
        if(user.getDbPrivilegeMap()!=null && user.getDbPrivilegeMap().size()>0){
            String dbMethod = null;
            if(method.startsWith(ManageContainer.db_insert)){
                dbMethod = ManageContainer.db_insert;
            }else if(method.startsWith(ManageContainer.db_update)){
                dbMethod = ManageContainer.db_update;
            }else if(method.startsWith(ManageContainer.db_delete)){
                dbMethod = ManageContainer.db_delete;
            }
            logger.error("optionMethod="+dbMethod);
            if(dbMethod!=null){
                logger.error
                user.getDbPrivilegeMap()="+user.getDbPrivilegeMap()+",method="+method);
                logger.error("user.getDbPrivilegeMap().get(optionMethod)="+user.getDbPrivilegeMap().get(dbMethod));
                String op = user.getDbPrivilegeMap().get(dbMethod);
                if(StringUtils.isBlank(op)){
                    if(dbMethod.equals(ManageContainer.db_insert)){
                        logger.error(ManageContainer.db_privilege_insert_error);
                        ServletActionContext.getRequest().getSession().setAttribute(ManageContainer.action_db_error, ManageContainer.db_privilege_insert_error);
                    }else if(dbMethod.equals(ManageContainer.db_update)){
                        logger.error(ManageContainer.db_privilege_update_error);
                        ServletActionContext.getRequest().getSession().setAttribute(ManageContainer.action_db_error, ManageContainer.db_privilege_update_error);
                    }else if(dbMethod.equals(ManageContainer.db_delete)){
                        logger.error(ManageContainer.db_privilege_delete_error);
                        ServletActionContext.getRequest().getSession().setAttribute(ManageContainer.action_db_error, ManageContainer.db_privilege_delete_error);
                    }else{
                    }
                    return not_db_privilege;
                }
            }
        }
        logger.error("ManageInterceptor.actionInvocation.invoke().");
        return actionInvocation.invoke();
        if(PrivilegeUtil.check(ServletActionContext.getRequest().getSession(), urlBuff.toString())){
            return actionInvocation.invoke();
        }else{
            logger.error;
            ServletActionContext.getResponse().sendRedirect(SystemManager.systemSetting.getManageHttp()+"/error.jsp");
            return not_privilege;
        }
        Object action = actionInvocation.getAction();
        if (action instanceof LoginAction) {
            System.out
                    .println("exit check login, because this is login action.");
            return actionInvocation.invoke();
        }
        Map session = actionInvocation.getInvocationContext().getSession();
        String login = (String) session.get(LOGIN_KEY);
        if (login != null && login.length() > 0) {
            System.out.println("already login!");
            return actionInvocation.invoke();
        } else {
            System.out.println("no login, forward login page!");
            return LOGIN_PAGE;
        }
    }
}